<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="base_top.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>欢迎登录</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<script type="text/javascript" src="<%=basePath%>js/jquery-1.8.3.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/user/cookie_code.js"></script>
	<script type="text/javascript">
		$(function () {
			var name_right = false;
			$("#user").blur(function() {
				var name = $(this).val().trim();
				if (name != "") {
					var phone =  /^1[3|4|5|8]\d{9}$/;
					var email = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
					if (phone.test(name) || email.test(name)) {
						name_right = true;
					} else {
						$("#nametip").show().delay(1000).hide(0);$("#nametip").show().delay(1000).hide(0);
					}
				}
			});
			
			$("#sub_btn").click(function() {
				var lName = $("#user").val().trim();
				var lPass = $("#pass").val().trim();
				if (lName != "" && lPass != "" && name_right) {
					//$("#login_form").submit();
					$.ajax({
	        			cache: false,
	        			url:"log/login",
	        			type: "POST",
	        			data: {luser: lName, lpass: lPass},
	        			dataType:"json",
	        		    success: function(data) {
	        		    	alert(data.msg + "--" + data.lalias);
	        		    	if (data.msg == "success") {
	        		    		setCookie('lAlias',data.lalias,1);
	            		    	setCookie('lName',data.luser,1);
	            		    	setCookie('lPass',data.lpass,1);
	            		    	location.href="selfCenter";
	        		    	}
	        		    },
	    				error: function() {
	    					clearCookies(ck);
	    				}
	        		});
				};
			});
			
		});
	
	</script>
  </head>
  
  <body>
  <form id="login_form" action="log/login" method="post">
  <label id="nametip" style="display:none;">请输入合法用户名</label>
    <table>
    	<tr>
    		<td>用户名</td><td><input id="user" type="text" name="user" /></td>
    	</tr>
    	<tr>
    		<td>密码</td><td><input id="pass" type="password" name="pass"/></td>
    	</tr>
    	<tr><td><input id="sub_btn" type="button" value="登录"/></td><td><a href="<%=basePath%>user/register.jsp">注册</a></td></tr>
    </table>
  </form>
  </body>
</html>
